<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp-head.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>${target}</title>

<script type="text/javascript">

	
	$(function() {
		
		dateView("dateView");

		$("#create").click(function() {
			$('#myForm').clearForm();
			$('#myForm').attr("action","/curd/create.action")
			$('#modal').modal('toggle');
		})
		
		$("#update").click(function() {
			
			var formId="myForm";
			
			var $tr=$(":radio[name=select_edit]:checked").parent().parent();
			
			var $tds=$tr.find("td");
			
			var $form=$("#"+formId)
			
			$form.clearForm();
			
			$tds.each(function(){
				var field=$(this).attr("field");
				var text=$(this).html();
				$form.find("[name="+field+"]").attr("value",text);
			})
			
			$('#myForm').attr("action","/curd/update.action")
			$('#modal').modal('toggle');
		})
		
		$("#delete").click(function() {
			
			answer=confirm("确认删除这条数据!!");
			
			if(answer == true)
			{

				var $tr=$(":radio[name=select_edit]:checked").parent().parent();
				
				var $form=$("#myForm");
				
				tr2form($tr,$form);
				
				$form.attr("action","/curd/delete.action")
				
				save('myForm','modal','dateView');
			}
			else
			{
			}
		})

	})
</script>
</head>

<body>
	<h2>${target}</h2>

	<button id="create" type="button" class="btn btn-primary">新建</button>
	<button id="update" type="button" class="btn btn-primary">编辑</button>
	<button id="delete" type="button" class="btn btn-primary">删除</button>
	<table id="dateView" url="/curd/read.action?target=${target}"
		class="table table-bordered table-hover">
		<thead>
			<tr>
				<th></th>
				<c:forEach items="${columns}" var="item">
					<th field="${item.name}">${item.name}</th>
				</c:forEach>
			</tr>
		</thead>
	</table>


	<div id="modal" class="modal hide fade">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			<h3>${target}</h3>
		</div>
		<div class="modal-body">
			<form id="myForm" class="form-horizontal">
				<input type="hidden" name="target" value="${target}"/>	
				<c:forEach items="${columns}" var="item">
				<div class="control-group">
					<label class="control-label" for="${item.name}">${item.name}</label>
					<div class="controls">
						<input type="text" id="${item.name}"  name="${item.name}">
					</div>
				</div>
				</c:forEach>	
			</form>
		</div>
		<div class="modal-footer">
			<a href="#" class="btn">关闭</a> <a href="#" class="btn btn-primary" onclick="save('myForm','modal','dateView')">保存</a>
		</div>
	</div>

</body>
</html>
